﻿using AutoMapper;
using CoreProject.DTO;
using CoreProject.IService;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CoreProject.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class GoodsTypeController : ControllerBase
    {
        private readonly IGoodsTypeService _service;
        private readonly IMapper _mapper;

        public GoodsTypeController(IGoodsTypeService service, IMapper mapper)
        {
            _service = service;
            _mapper = mapper;
        }
        // GET: api/<GoodsTypeController>
        [HttpGet]
        public async Task<ResultData<List<GoodTypeDto>>> Get()
        {
            var data = await _service.GetListAsync(true, r => r.GtId, r => true);
            var list = _mapper.Map<List<GoodTypeDto>>(data);
            ResultData<List<GoodTypeDto>> result = new ResultData<List<GoodTypeDto>>();
            result.code = "1";
            result.msg = "ok";
            result.state = 200;
            result.data = list;
            return result;
        }


    }
}
